package xyz.xtt.equity.enums;

import java.util.Arrays;
import java.util.Objects;

import com.google.common.primitives.Ints;

import xyz.xtt.asset.api.enums.DealStateEnum;

/**
 * 权限兑换表
 * 
 * @author huqibo
 * @date 2025/12/30
 */
public enum EntitlementDeliverResultEnum {
	/**
	 * 已退款
	 */
	FAIL(0, "失败"),

	/**
	 * 成功
	 */
	ALL_SUCC(1, "成功"),

	/**
	 * 部分成功
	 */
	ANY_SUCC(2, "部分成功"),;

	/**
	 * 编码
	 */
	private int code;
	/**
	 * 描述
	 */
	private String desc;

	EntitlementDeliverResultEnum(int code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	public int code() {
		return code;
	}

	public String desc() {
		return desc;
	}

	public static boolean checkType(String checkType) {
		return Arrays.asList(DealStateEnum.values()).stream().anyMatch(x -> Objects.equals(x.name(), checkType));
	}

	public static EntitlementDeliverResultEnum convert(String checkType) {
		return Arrays.asList(EntitlementDeliverResultEnum.values()).stream().filter(x -> Objects.equals(x.name(), checkType)).findFirst().orElse(null);
	}

	public static EntitlementDeliverResultEnum queryConvert(String checkType) {
		return Arrays
				.asList(EntitlementDeliverResultEnum.values())
				.stream()
				.filter(x -> Objects.equals(x.code(), Ints.tryParse(checkType)))
				.findFirst()
				.orElse(null);
	}
}
